package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.entity.SysUser;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TStation;
import com.ruoyi.system.service.ITStationService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 站点管理Controller
 * 
 * @author 小卤
 * @date 2025-04-04
 */
@RestController
@RequestMapping("/system/station")
public class TStationController extends BaseController
{
    @Autowired
    private ITStationService tStationService;

    /**
     * 查询站点管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:station:list')")
    @GetMapping("/list")
    public TableDataInfo list(TStation tStation)
    {
        startPage();
        List<TStation> list = tStationService.selectTStationList(tStation);
        return getDataTable(list);
    }

    @GetMapping("/getAll")
    public AjaxResult getAll()
    {
        List<TStation> list = tStationService.getAll();
        return success(list);
    }

    /**
     * 导出站点管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:station:export')")
    @Log(title = "站点管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TStation tStation)
    {
        List<TStation> list = tStationService.selectTStationList(tStation);
        ExcelUtil<TStation> util = new ExcelUtil<TStation>(TStation.class);
        util.exportExcel(response, list, "站点管理数据");
    }

    /**
     * 获取站点管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:station:query')")
    @GetMapping(value = "/{stationId}")
    public AjaxResult getInfo(@PathVariable("stationId") Long stationId)
    {
        return success(tStationService.selectTStationByStationId(stationId));
    }

    /**
     * 新增站点管理
     */
    @PreAuthorize("@ss.hasPermi('system:station:add')")
    @Log(title = "站点管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TStation tStation)
    {
        return toAjax(tStationService.insertTStation(tStation));
    }

    /**
     * 修改站点管理
     */
    @PreAuthorize("@ss.hasPermi('system:station:edit')")
    @Log(title = "站点管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TStation tStation)
    {
        return toAjax(tStationService.updateTStation(tStation));
    }

    /**
     * 删除站点管理
     */
    @PreAuthorize("@ss.hasPermi('system:station:remove')")
    @Log(title = "站点管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{stationIds}")
    public AjaxResult remove(@PathVariable Long[] stationIds)
    {
        return toAjax(tStationService.deleteTStationByStationIds(stationIds));
    }

    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response)
    {
        ExcelUtil<TStation> util = new ExcelUtil<TStation>(TStation.class);
        util.importTemplateExcel(response, "站点数据");
    }

    @PostMapping("/importData")
    @ResponseBody
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<TStation> util = new ExcelUtil<TStation>(TStation.class);
        List<TStation> stationList = util.importExcel(file.getInputStream());
        String message = tStationService.importStation(stationList, updateSupport);
        return AjaxResult.success(message);
    }
}
